package edu.hawaii.wicket.page.ac;

import java.util.Map;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import edu.hawaii.wicket.ExampleApplicationSession;
import edu.hawaii.wicket.page.BasePage;
import edu.hawaii.wicket.page.ExternalImageUrl;
import edu.hawaii.wicket.page.aquaponics.AquaponicsPage;
import edu.hawaii.wicket.page.lighting.LightingPage;
import edu.hawaii.wicket.page.security.SecurityPage;
import edu.hawaii.wicket.page.water.WaterPage;

/**
 * Creates the ACPage for the SolarDecathlon system.
 * @author Gregory L. Burgess
 *
 */
public class ACPage extends BasePage {

    private static final ResourceReference SIDE_BAR = new ResourceReference(
            ACPage.class,"side-bar.png");
    private static final ResourceReference LOGO = new ResourceReference(
            ACPage.class,"logo.png");  
  
  private static final long serialVersionUID = 1L;
  /**
   * Creates the AC page.
   */
  public ACPage() {
    

    //form to pass data
    Form<String> form = new Form<String>("form");
    add(form);
    add(new Image("sidebar", new Model<ResourceReference>(SIDE_BAR)));
    add(new Image("logo", new Model<ResourceReference>(LOGO)));

    //data output for water heater settings
    form.add(new Label("budgetRem", "185"));
    form.add(new Label("timeRem", "224"));
    form.add(new Label("currConsump", "1.2 KWH"));
    form.add(new Label("approxCost", "$1.20"));
    form.add(new Label("airExRate", "10%"));
    form.add(new Label("outAirQual", "94"));
    form.add(new Label("inAirQual", "97"));
    //fields for smart temp
    form.add(new TextField<String>("temp"));
    form.add(new TextField<String>("humidity"));
    form.add(new TextField<String>("ventilation"));
    form.add(new TextField<String>("timer"));
    
    //manual control for shower temp
    form.add(new Button("change") {
      private static final long serialVersionUID = 1L;

      /** Display the page again, now with the updated values of field1 and field2. */
      @Override
      public void onSubmit() {

        setResponsePage(new ACPage());
      }
    });
    
    //radio buttons for water heater on/off switch
    RadioGroup<String> group = new RadioGroup<String>("power");
    group.add(new Radio<String>("on"));
    group.add(new Radio<String>("off"));
    form.add(group);
    
    //long URL is long...
    String url = "http://chart.apis.google.com/chart?chf=bg,s,000000&chxl=0:";
    url += "|2%3A00|3%3A00|4%3A00|5%3A00|6%3A00|7%3A00|8%3A00|9%3A00|10%3A00|";
    url += "11%3A00|12%3A00&chxp=0,2,10,20,30,40,50,60,70,80,90,100&chxr=1,0,2";
    url += "&chxs=1,676767,11.5,0,lt,676767&chxtc=1,10&chxt=x,y&chs=800x310&cht=";
    url += "lc&chco=3D7930&chd=s:QnvphibY&chg=14.3,-1,1,1&chls=3,4,0&chma=|3&chm=B,00800085,";
    url += "0,0,0,-1&chtt=AC+Energy+Usage+Over+Time+(KWH)&chts=FFFFFF,15";
   
    form.add(new ExternalImageUrl("ACChart", url,"800","270"));

    ResourceReference house = new ResourceReference(ACPage.class,"house.png");
    form.add(new Image("house", new Model<ResourceReference>(house)));
     
    //=========================================================================================
  //=========================================================================================
  //=========================================================================================
  //=========================================================================================
 // Now add the links that go in the tabs. 
    add(new Link<String>("AquaponicsPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to HomePage. */
      @Override
      public void onClick() {
        setResponsePage(new AquaponicsPage());
      }
      }
    );
    
    add(new Link<String>("LightingPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to ListPage. */
      @Override
      public void onClick() {
        setResponsePage(new LightingPage());
      } 
      }
    );
    
    add(new Link<String>("SecurityPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new SecurityPage());
      }
      }
    );
    
    add(new Link<String>("ClimatePageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to TablePage. */
      @Override
      public void onClick() {
        setResponsePage(new ACPage());
      }
      }
    );
    
    add(new Link<String>("WaterPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to TablePage. */
      @Override
      public void onClick() {
        setResponsePage(new WaterPage());
      }
      }
    );
    
 
  }
  
  /**
   * Returns the property map associated with this user's session.
   * @return The session's property map.
   */
  public Map<String, String> getSessionProperties() {
    return ((ExampleApplicationSession)getSession()).getProperties();   
  }
}
